const cryptoJs = require("crypto-js")

function aesEncrypt(str, key, iv) {
    return cryptoJs.AES.encrypt(str, key, { iv: iv, padding: cryptoJs.pad.Pkcs7, mode: cryptoJs.mode.ECB })
}

function aesDecrypt(encrypted, key) {
    return cryptoJs.AES.decrypt(encrypted, key, { padding: cryptoJs.pad.Pkcs7, mode: cryptoJs.mode.ECB })
}

let content = cryptoJs.enc.Utf8.parse("a")
let key = cryptoJs.enc.Utf8.parse("3TXr!JXCc4YyzGzD")
let iv = cryptoJs.enc.Latin1.parse("0")
console.log(key)
console.log(content.toString(cryptoJs.enc.Hex))

let aEncrpted = aesEncrypt(content, key, iv)
// console.log(aEncrpted)
console.log('BASE64 key: ' + cryptoJs.enc.Base64.stringify(key))
console.log('aes1: ' + cryptoJs.AES.encrypt('aaa', 'secret key 123'))
console.log('aes2 base64: ' + aEncrpted)
console.log(`aes utf8: ${aEncrpted.toString(cryptoJs.enc.Utf8)}`)
console.log('aes2 hex: ' + aEncrpted.ciphertext)

let decrypted = aesDecrypt(aEncrpted.toString(), key)
console.log(decrypted)
console.log(`decrypted text: ${decrypted.toString(cryptoJs.enc.Utf8)}`)
